package com.hmily.dubbo.consumer.sync;

import com.hmily.dubbo.api.UserQueryFacade;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;

import java.io.IOException;

/**
 * <h1>三多配置 -- 多注册中心配置。</h1>
 *
 * @author hmilyylimh
 *         ^_^
 * @version 0.0.1
 *         ^_^
 * @date 2021-11-02
 *
 */
public class ThreeCfgRegistryConsumerApplication {

    public static void main(String[] args) throws IOException {
        // 设置应用服务名称
        ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-consumer");
        // 设置注册中心的地址
        RegistryConfig registryConfig = new RegistryConfig("redis://127.0.0.1:6379");

        // 创建引用 UserQueryFacade 这个服务的对象
        ReferenceConfig<UserQueryFacade> referenceConfig = new ReferenceConfig<>();
        referenceConfig.setApplication(applicationConfig);
        referenceConfig.setRegistry(registryConfig);
        referenceConfig.setInterface(UserQueryFacade.class);
        // referenceConfig.setProtocol("dubbo");

        // 直接拿到引用的代理对象，然后进行远程调用
        UserQueryFacade userQueryFacade = referenceConfig.get();
        System.out.println(userQueryFacade.queryUser("G314"));
        System.out.println(userQueryFacade.queryUser("G314"));
        System.out.println(userQueryFacade.queryUser("G314"));
        System.out.println(userQueryFacade.queryUser("G314"));
        System.out.println(userQueryFacade.queryUser("G314"));

        // 阻塞等待
        System.in.read();
    }
}
